//app.js
var comment = require("../../utils/utils.js");
var app = getApp();
var that;

Page({
	data: {
		userInfo : '',
		page_index: 0,
		orderList: [],
		loadingTip: '',
		isAdmin: wx.getStorageSync('isAdmin'),
		visual: 'hidden'
	},
	onLoad: function () {
		that = this;
	},
	showDetail: function (e) {
		var index = e.currentTarget.dataset.index;
		// 传递订单objectId
		wx.navigateTo({
			url: '../detail/detail?objectId=' + that.data.orderList[index].orderId
		})
	},
	onShow: function () {
		that.loadOrder();
		that.setData({
			userInfo : app.globalData.userInfo
		})
	},
	loadOrder: function () {
		//查询所有订单
		wx.request({
			url: comment.baseUrl + "/wx/orders/queryOrder",
			data: {
				userId: app.globalData.openId
			},
			success: function (results) {
				// 请求成功将数据存入orderList
				results = results.data;
				that.setData({
					orderList: results,

				});
				// holder
				that.setData({
					visual: results.length == 0 && that.data.page_index == 0 ? 'show' : 'hidden'
				});
			}
		});
	},
	onReachBottom: function () {
		that.setData({
			page_index: ++that.data.page_index
		});
		that.loadOrder();
	},
	payment: function (e) {
		var index = e.currentTarget.dataset.index;
		var order = that.data.orderList[index];
		comment.payment(order,1);
	}
})